package com.usian.controller;


import cn.hutool.db.sql.Order;
import com.usian.common.R;
import com.usian.entity.ResultResponse;
import com.usian.service.IOrderService;


import com.usian.model.address.Address;
import com.usian.model.goods.Goods;
import com.usian.model.orders.OrderAddRequest;
import com.usian.model.orders.Orders;
import com.usian.vo.OrderIdVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-17
 */
@RestController
@RequestMapping("/orders")
@Slf4j
public class OrderController {

    @Autowired
    private IOrderService orderService;

    //order表查询所有
    @PostMapping("/findAll")
    public List<Orders> findAll() {
        return orderService.findAll();
    }
    @RequestMapping("orderAdd")
    public ResultResponse orderAdd(@RequestBody OrderAddRequest request) {
        Integer id = request.getId();
        Goods goods = request.getGoods();
        Address address = request.getAddress();
        Integer number = request.getNumber();
        // 在这里进行后续的业务逻辑处理，比如将订单数据保存到数据库等操作
        return orderService.orderAdd(id, goods, address,number);
    }

    //用户未支付生成订单接口
    @RequestMapping("/orderAddGuan")
    public ResultResponse orderAddGuan(@RequestBody OrderAddRequest request) {
        Integer id = request.getId();
        Goods goods = request.getGoods();
        Address address = request.getAddress();
        Integer number = request.getNumber();
        // 在这里进行后续的业务逻辑处理，比如将订单数据保存到数据库等操作
        return orderService.orderAddGuan(id, goods, address,number);
    }
    //根据订单编号查询订单信息  ---  返回订单信息给前端
    @GetMapping("/findByOrderId")
    public ResultResponse findOrdersByOrderId(String findId) {
        log.info("订单编号：" + findId);
        return orderService.findOrdersByOrderId(findId);
    }
    @RequestMapping("orderAdd02")
    public ResultResponse orderAdd02(@RequestBody Orders orders) {
        log.info("订单数据：" + orders);
        return orderService.orderAdd02(orders);
    }
    @RequestMapping("/findById")
    public R findById(Integer id){
        Orders orders = orderService.findById(id);
        return R.success(orders);
    }
    //取消订单
    @RequestMapping("/removeOrder")
    public ResultResponse removeOrder(String findId){
        System.out.println(findId);
        return orderService.removeOrder(findId);
    }

    @RequestMapping("/status")
    public R status(Integer id){
        return R.success(orderService.status(id));
    }
    //确认收货
    @RequestMapping("/confirmReceipt")
    public ResultResponse confirmReceipt(String findId){
        return orderService.confirmReceipt(findId);
    }
}
